//
//  BaseController.swift
//  swift-微博
//
//  Created by chenrin on 2016/12/14.
//  Copyright © 2016年 zhuoheng. All rights reserved.
//

import UIKit

class BaseController: UITableViewController {
    
     var viditorView : VisitorView?
    
    //定义一个变量保存用户当前是否登录
    var userLogin = OAuthModel.userLogin()
    override func loadView() {
       
        userLogin ? super.loadView() : setupVisitorView()
        
    }
    //没有登录的状态
    func setupVisitorView() {
        
        let customView = VisitorView()
        customView.visitorViewDelegate = self
        view = customView
        viditorView = customView
        //设置导航栏的item
        
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "登录", style: .plain, target: self, action: #selector(visitorViewLogin))
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "注册", style: .plain, target: self, action: #selector(visitorViewRegister))
    }
    
    
}

// MARK:- 协议方法
extension BaseController : VisitorViewDelegate{
    //弹出登录界面
   @objc func visitorViewLogin() {
        let oAuthVc = QAuthController()
    let nav = UINavigationController.init(rootViewController: oAuthVc)
    
     self.present(nav, animated: true, completion: nil)
    }
    func visitorViewRegister() {
        
    }
    
}
